import requests
from api import Api
from Bean import Bean

session = requests.session()
headers = {
    "User-Agent": "Mozilla/5.0 (Linux; Android 5.1.1; vivo Xplay5A Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 MicroMessenger/7.0.10.1580(0x27000A55) Process/appbrand0 NetType/WIFI Language/zh_CN ABI/arm64",
    "content-type": "application/json;charset=utf-8",
    'Connection': 'keep-alive'
}


def get_data():
    api = Api()
    bean = Bean()
    for item in bean.get_goods_list():
        goods = api.get_goods(item)
        if goods:
            code = goods['code']
            print(goods['msg'])
            if code == 200:
                contents = goods['data']['content']
                for content in contents:
                    topLevelId = item['topLevelId']
                    productId = content['id']
                    print("topLevelId=" + topLevelId + ",productId=" + productId)
                    details = bean.get_goods_details_body_params(topLevelId, productId)
                    text = api.goods_detail(details)
                    print(text)

            elif code == 1929:
                # 需要登录

                pass


if __name__ == '__main__':
    api = Api()
    hasGoodsList = api.check_goods_has()
    print(f"有货总结总数{len(hasGoodsList)}=========================")
    print(hasGoodsList)
